package cc.rengu.redp.bizimpl.upmp.service.impl;/*
package cc.rengu.redp.bizimpl.upmp.service.impl;

import cc.rengu.ecp.core.exception.RedpException;
import cc.rengu.ecp.core.pagination.GroupPropertyFilter;
import cc.rengu.ecp.core.pagination.PropertyFilter;
import cc.rengu.ecp.core.util.Common;
import cc.rengu.ecp.core.util.DateUtils;
import cc.rengu.ecp.core.util.GZIPUtils;
import cc.rengu.ecp.core.web.view.OperationResult;
import cc.rengu.ecp.platform.mcmp.common.BusinessContainer;
import cc.rengu.ecp.platform.mcmp.entity.BizTmp;
import cc.rengu.ecp.platform.mcmp.entity.UpmpPrivilegeCheck;
import cc.rengu.ecp.platform.mcmp.enums.BizDataAuditStatusEnum;
import cc.rengu.ecp.platform.mcmp.enums.BizDataStatusEnum;
import cc.rengu.ecp.platform.mcmp.enums.BizOprEnum;
import cc.rengu.ecp.platform.mcmp.enums.PageOptFlagEnum;
import cc.rengu.ecp.platform.module.auth.entity.UpmpOrganization;
import cc.rengu.redp.bizimpl.constant.UpmpConstant;
import cc.rengu.redp.bizimpl.upmp.dao.TermBrandInfoMapper;
import cc.rengu.redp.bizimpl.upmp.domain.TermBrandInfo;
import cc.rengu.redp.bizimpl.upmp.service.IBizTmpService;
import cc.rengu.redp.bizimpl.upmp.service.IUpmpOrganizationService;
import cc.rengu.redp.bizimpl.upmp.service.IUpmpPrivilegeCheckService;
import cc.rengu.redp.bizimpl.upmp.service.IUpmpSysParamService;
import cc.rengu.redp.bizimpl.upmp.vo.UpmpUserInfoVO;
import cc.rengu.redp.bizimpl.utils.CommonUtils;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.SQLQuery;
import org.hibernate.transform.Transformers;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.TransactionCallbackWithoutResult;
import org.springframework.transaction.support.TransactionTemplate;
import org.springframework.ui.Model;

import javax.persistence.Query;
import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.*;

*/
/**
 *	对TermBrand实体提供服务
 *
 * @author zhuyaping
 * @date 2016年09月06日06时52分
 *
 *	@see
 *//*


@Service
@Transactional
public class TermBrandNewService extends ServiceImpl<TermBrandInfoMapper,TermBrandInfo> {
    

    @Autowired
    private TransactionTemplate transactionTemplate;

    @Autowired
    private IBizTmpService bizTmpService;

    @Autowired
    private IUpmpSysParamService upmpSysParamService;

    @Autowired
    private IUpmpOrganizationService organizationService;



    public Map<String, Object> termbrandSelect2List(HttpServletRequest request)throws RedpException{
        String q = request.getParameter("q");
        if(null==q){
            return null;
        }
        q=q.replaceAll("&amp;", "&");
        String[] param = q.split("&");
         UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
        String org = user.getOrgCode().toString();

        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
        String dateTime = sdf.format(new Date());
        //request.setAttribute("search['BW_id']", Long.parseLong(param[0]));
        if(null!=param&&param.length>0){
            request.setAttribute("search['CN_brandCode_OR_brandName']", param[0]);
        }
        request.setAttribute("search['EQ_status']", "01");
        if(user.isAdmin() && param.length > 1){
            request.setAttribute("search['EQ_instId']", param[1]);
        }else{
            request.setAttribute("search['IN_crtOrgId']", GZIPUtils.uncompressToString(user.getUserOrgCodes()));
        }
        GroupPropertyFilter groupPropertyFilter=GroupPropertyFilter.buildFromHttpRequest(TermBrandInfo.class, request);
        Pageable pageable = (Pageable)PropertyFilter.buildPageableFromHttpRequest(request);
        */
/*构建pageable时需要放入request里面的参数
        "rows"-每页多少行
        "page"-当前页
        "start"-起始行 ，可以不提供，默认为page*rows
        *//*

        Page<TermBrandInfo> page =  this.findByPage(groupPropertyFilter, pageable);
        List<TermBrandInfo> listx = page.getContent();
        Map<String, Object> maps = new HashMap<String, Object>();
        // Map<String,Long> map = new HashMap<String,Long>();
        Map<String, String> map = new HashMap<String, String>();
        List<Object> list = new ArrayList<Object>();
        if (listx != null) {
            for(int i=0;i<listx.size();i++){
                TermBrandInfo tb = listx.get(i);
                map = new HashMap<String, String>();
                map.put("id",tb.getBrandCode());
                map.put("name",tb.getBrandName());
                map.put("desc",tb.getBrandDesc());

                list.add(map);
            }
      */
/*  for(int i=0;i<listx.size();i++){
        	TermBrandInfo tb = listx.get(i);
          map1 = new HashMap<String,String>();

         map1.put("name",tb.getBrandName());
         // map.put("desc",tb.getBrandDesc());
          list.add(map1);
        }*//*

            maps.put("results", list);
            maps.put("more", false);
        }
        return maps;
    }

    public List<String> findAllbrandCd() throws RedpException{
        // TODO Auto-generated method stub
        return this.findAllbrandCd();
    }

    public List<String> findAllbrandName(String brandcd) {
        // TODO Auto-generated method stub
        return this.findAllbrandName( brandcd);
    }
    public List<String> findAllbrandName()throws RedpException {
        // TODO Auto-generated method stub
        return this.findAllbrandName();
    }
    public TermBrandInfo findTermBrand(String brandCode) throws RedpException{
        // TODO Auto-generated method stub
        return this.findbrandCode(brandCode);
    }
    public List<TermBrandInfo> findbrandByName(String brandName){
        return this.findbrandByName(brandName);
    }

    */
/**
     * 查询终端品牌及终端品牌下的型号数量
     * @param request
     * @param model
     * @return
     *//*

    public Page<Map> termbrandSelectList(HttpServletRequest request, Model model)throws RedpException {
        Page<Map> page;
        String defaultRows = request.getParameter(BusinessContainer.ECP_DEFAULTROWS_PARA_NAME);
        if(StringUtils.isBlank(defaultRows))defaultRows = BusinessContainer.ECP_PAGE_DEFAULTROWS;
        Pageable pageable = PropertyFilter.buildPageableFromHttpRequest(request, Integer.parseInt(defaultRows));

         UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
        StringBuffer param = new StringBuffer();
        String userOrgCodes = GZIPUtils.uncompressToString(user.getUserOrgCodes());
        String status= BusinessContainer.status_00;
        String reqparam = request.getParameter("search['CN_brandCode_OR_brandName_OR_brandDesc']");
        if(!StringUtils.isBlank(reqparam)){
            param.append(" and (a.BRAND_CODE like '%"+reqparam+"%' or a.BRAND_NAME  like '%"+reqparam+"%' or a.BRAND_DESC  like '%"+reqparam+"%' ) ");
        }
        if (null != user && user.isAdmin()) {
            String instId = request.getParameter("instId");
            param.append(" and  a.inst_id = '"+instId+"' ");
        }else{
            param.append(" and  a.crt_org_id in ("+userOrgCodes+") ");
        }
        StringBuffer sql = new StringBuffer();
        sql.append(" select count(b.brand_code)as \'xhsl\',a.id as \'id\',a.brand_code as \'brandCode\',a.brand_name as \'brandName\',a.brand_desc as \'brandDesc\',a.contact_name as \'contactName\',a.contact_phone as \'contactPhone\',a.contact_email as \'contactEmail\',a.status as \'status\',a.crt_org_id as \'crtOrgId\',a.opr_id as \'oprId\',a.CREATE_TIME as \'createTime\',a.LAST_OPR_ID as \'lastOprId\',a.last_update_time as \'lastUpdateTime\',a.last_audit_id as \'lastAuditId\',a.last_audit_time as \'lastAuditTime\',a.inst_id as \'instId\',a.status as \'status1\',a.audit_status as \'auditStatus\' from T_B_TERM_BRAND_INFO a \n");
        sql.append("left join T_B_TERM_MODEL_INFO b on a.brand_code=b.brand_code  and (b.status=00 or b.status=01)  ");

        if (null != user && user.isAdmin()) {
            String instId = request.getParameter("instId");
            if(!StringUtils.isBlank(instId)){
                sql.append(" where a.inst_id  = '"+instId+"' ");
            }
        }
        sql.append("  group by b.brand_code,a.id,a.brand_code,a.brand_name,a.brand_desc,a.contact_name,a.contact_phone,a.contact_email,a.status,a.crt_org_id,a.OPR_ID,a.CREATE_TIME,a.LAST_OPR_ID,a.last_update_time,a.last_audit_id,a.last_audit_time,a.inst_id,a.status,a.audit_status  having (a.status=00 or a.status=01)");
        try{
            if(StringUtils.isNotBlank(sql)){
                sql.append(param);
                log.debug("终端品牌列表数据加载查询SQL:[{}]",sql.toString());
                Query query = this.getEntityManager().createNativeQuery(sql.toString());
                ((SQLQuery)query.unwrap(SQLQuery.class)).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);


                Object count = query.getResultList().size();

                query.setFirstResult(pageable.getOffset()).setMaxResults(pageable.getPageSize());

                page = new PageImpl<>(query.getResultList(), pageable, Long.valueOf(count.toString()).longValue());

//		    	page = this.findByPageNativeSQL(pageable, sql.toString());
                model.addAttribute("pageData", page);
                model.addAttribute("error","");
            }else{
                model.addAttribute("error","");
                page = new PageImpl<>(new ArrayList<Map>(), pageable, 0);
                model.addAttribute("pageData", page);
            }
        }catch(Exception e){
            model.addAttribute("error", "sql异常,请检查sql语句的正确性!");
            page = new PageImpl<>(new ArrayList<Map>(), pageable, 0);

            model.addAttribute("pageData", page);
             log.error(e.getMessage());
        }
        return page;
    }

    public OperationResult saveData(String oprMenuId, String oprMenuName, TermBrandInfo entity, UpmpUserInfoVO user, UpmpOrganization org, IUpmpPrivilegeCheckService authPrivilegeCheckService, HttpServletRequest request, String webNextUrl) throws RedpException{
        String flag = request.getParameter("optFlag");
        String id = request.getParameter("id");
        String brandName = request.getParameter("brandName");
        String brandCode = request.getParameter("brandCode");
        Map<String, Object> result = com.google.common.collect.Maps.newHashMap();
        String lastUpddt = DateUtils.formatDate(new Date(), "yyyy-MM-dd HH:mm:ss.SSS");
        TermBrandInfo oldEntity = null;
        if (!PageOptFlagEnum.OPT_FLAG_ADD.getType().equals(flag)){
            oldEntity = this.getById(id);
        }
        if (PageOptFlagEnum.OPT_FLAG_ADD.getType().equals(flag)) {
            String instId = upmpSysParamService.getById(UpmpConstant.IGAS_DEFAULT_INST_ID).getPrimaryValue();
        // 获取渠道ID：固定20
        String channelId = CommonUtils.getChannelId(upmpSysParamService, instId);
            entity.setId(null);
            if (this.findAllbrandName().contains(brandName)) {
                return OperationResult.buildFailureResult("终端品牌名重复,请重新填写", result);
            }
            brandCode = BusinessContainer.BrandCd_PREFIX + String.format("%06d", Integer.parseInt(upmpSysSeqService
                    .updateParamValue(BusinessContainer.COMM_PARAM_CODE, BusinessContainer.BrandCd_PREFIX, channelId)));
            if (this.findAllbrandCd().contains(brandCode)) {
                return OperationResult.buildFailureResult("终端品牌代码重复,联系管理员", result);
            } else {
                entity.setBrandCode(brandCode);
            }
            UpmpPrivilegeCheck privilegeCheck = authPrivilegeCheckService.getPrivilegeCheckByPrivilegeCode(user.getInstId(),"终端品牌管理:新增");
            if (null!=privilegeCheck&& BusinessContainer.YES.equals(privilegeCheck.getChecked())) {
                //需要审核
                entity.setOprId(user.getId());
             //   entity.setCrtOrgId(org.getOrgCode());
                entity.setCreateTime(lastUpddt);
                entity.setStatus(BizDataStatusEnum.STATUS_DRAFT.getType());
                entity.setAuditStatus(BizDataAuditStatusEnum.AUDIT_STATUS_ADD_CHECKING.getType());
                save(entity);

                bizTmpService.saveBizTmp(entity, user, org.getInstId(), BizOprEnum.OPR_ADD.getType(), lastUpddt
                        , oprMenuId, oprMenuName, entity.getStatus(), entity.getAuditStatus(), String.valueOf(entity.getId()), webNextUrl,null,null,null);
                result.put("id", entity.getId());
            } else {
                //不需要审核
                entity.setOprId(user.getId());
         //       entity.setCrtOrgId(org.getOrgCode());
                entity.setCreateTime(lastUpddt);
                entity.setStatus(BizDataStatusEnum.STATUS_NORMAL.getType());
                entity.setAuditStatus(BizDataAuditStatusEnum.AUDIT_STATUS_ADD_PASS.getType());
                save(entity);

                bizHisService.saveBizHisNew(entity,entity, user, org.getInstId(), BizOprEnum.OPR_ADD.getType(), lastUpddt
                        , oprMenuId, oprMenuName, String.valueOf(entity.getId()),null,null,null);
                result.put("id", entity.getId());
            }
        } else if (PageOptFlagEnum.OPT_FLAG_UPDATE.getType().equals(flag)) {
            if (Common.isBlank(id)) {
                 log.error("请求参数(id)异常!");
                return OperationResult.buildFailureResult("请求参数(id)异常!", result);
            }
            if (this.findAllbrandName(id).contains(brandName)) {
                return OperationResult.buildFailureResult("终端品牌名重复,请重新填写", result);
            }
            UpmpPrivilegeCheck privilegeCheck = authPrivilegeCheckService.getPrivilegeCheckByPrivilegeCode(user.getInstId(), "终端品牌管理:修改");
            if (null!=privilegeCheck&& BusinessContainer.YES.equals(privilegeCheck.getChecked())) {
                //需要审核
                entity.setAuditStatus(BizDataAuditStatusEnum.AUDIT_STATUS_UPD_CHECKING.getType());
                entity.setLastOprId(user.getId());
                entity.setLastUpdateTime(lastUpddt);
                this.updateAuditStatus(id,entity.getAuditStatus());//只修改状态

                bizTmpService.saveBizTmp(entity, user, org.getInstId(), BizOprEnum.OPR_UPDATE.getType(), lastUpddt
                        , oprMenuId, oprMenuName, entity.getStatus(), entity.getAuditStatus(), String.valueOf(entity.getId()), webNextUrl,null,null,null);
                result.put("id", entity.getId());
            } else {
                entity.setAuditStatus(BizDataAuditStatusEnum.AUDIT_STATUS_UPD_PASS.getType());
                entity.setLastOprId(user.getId());
                entity.setLastUpdateTime(lastUpddt);
                TermBrandInfo termBrand = this.getById(id);
                BeanUtils.copyProperties(entity, termBrand);
                this.save(termBrand);

                bizHisService.saveBizHisNew(termBrand,oldEntity, user, org.getInstId(), BizOprEnum.OPR_UPDATE.getType(), lastUpddt
                        , oprMenuId, oprMenuName, String.valueOf(termBrand.getId()),null,null,null);
            }
        } else if (PageOptFlagEnum.OPT_FLAG_CHECK.getType().equals(flag)) {
            if (Common.isBlank(id)) {
                 log.error("请求参数(id)异常!");
                return OperationResult.buildFailureResult("请求参数(id)异常!", result);
            }
            //获取临时表数据并转换成实体对象
            BizTmp tmp = bizTmpService.getById(id);
            if (Common.isBlank(tmp)) {
                 log.error("根据id没有找到指定临时表数据！");
                return OperationResult.buildFailureResult("根据id没有找到指定临时表数据！", result);
            }
            String bizdata = "";
            if (null != tmp.getBizData1()) {
                bizdata += tmp.getBizData1();
            }
            if (null != tmp.getBizData2()) {
                bizdata += tmp.getBizData2();
            }
            if (null != tmp.getBizData3()) {
                bizdata += tmp.getBizData3();
            }

            TermBrandInfo termBrandNew = JSON.parseObject(bizdata, TermBrandInfo.class);

            TermBrandInfo termBrand = this.getById(id);
            // 备份正式表数据
            TermBrandInfo termBrandOld = new TermBrandInfo();
            BeanUtils.copyProperties(termBrand, termBrandOld);
            if (Common.isBlank(termBrand)) {
                 log.error("根据id没有找到指定数据！");
                return OperationResult.buildFailureResult("根据id没有找到指定数据！", result);
            }
            String opt = request.getParameter("opt");
            if (Common.isBlank(opt)) {
                logger.error("请求参数(opt)异常!");
                return OperationResult.buildFailureResult("请求参数(opt)异常!", result);
            }
            //校验终端品牌名称不能重复
            if ("pass".equals(opt) && this.findAllbrandName(id).contains(termBrandNew.getBrandName())) {
                return OperationResult.buildFailureResult("终端品牌名重复,请审核拒绝退回重新修改", result);
            }
            String bizOpr = "";
            if (BizDataAuditStatusEnum.AUDIT_STATUS_UPD_CHECKING.getType().equals(termBrand.getAuditStatus())) {
                if (!PageOptFlagEnum.OPT_FLAG_PASS.getType().equals(opt)) {

                } else{
                    BeanUtils.copyProperties(termBrandNew, termBrand);
                }
            }else{
                BeanUtils.copyProperties(termBrandNew, termBrand);
            }

            String auditRefuseReason = request.getParameter("auditRefuseReason");
            if (BizDataAuditStatusEnum.AUDIT_STATUS_ADD_CHECKING.getType().equals(termBrand.getAuditStatus())) {
                if (PageOptFlagEnum.OPT_FLAG_PASS.getType().equals(opt)) {
                    termBrand.setAuditStatus(BizDataAuditStatusEnum.AUDIT_STATUS_ADD_PASS.getType());
                    termBrand.setStatus(BizDataStatusEnum.STATUS_NORMAL.getType());
                } else {
                    termBrand.setAuditStatus(BizDataAuditStatusEnum.AUDIT_STATUS_ADD_REJECT.getType());
                }
                bizOpr = BizOprEnum.OPR_ADD.getType();
            } else if (BizDataAuditStatusEnum.AUDIT_STATUS_UPD_CHECKING.getType().equals(termBrand.getAuditStatus())) {
                if (PageOptFlagEnum.OPT_FLAG_PASS.getType().equals(opt)) {
                    termBrand.setAuditStatus(BizDataAuditStatusEnum.AUDIT_STATUS_UPD_PASS.getType());
                    termBrand.setStatus(BizDataStatusEnum.STATUS_NORMAL.getType());
                } else {
                    termBrand.setAuditStatus(BizDataAuditStatusEnum.AUDIT_STATUS_UPD_REJECT.getType());
                }
                bizOpr = BizOprEnum.OPR_UPDATE.getType();
            }
            termBrand.setAuditRefuseReason(auditRefuseReason);
            this.save(termBrand);
            if (PageOptFlagEnum.OPT_FLAG_PASS.getType().equals(opt)) {
                //审批通过将正式表更新到历史表
                bizHisService.saveBizHisNew(termBrand,termBrandOld, user, org.getInstId(), bizOpr, lastUpddt
                        , oprMenuId, oprMenuName, String.valueOf(termBrand.getId()),null,null,null);
            }
            // 修改临时表的审核状态等字段
            bizTmpService.saveBizTmp(termBrand, user, org.getInstId(), bizOpr, lastUpddt, oprMenuId, oprMenuName, termBrand.getStatus(), termBrand.getAuditStatus(), String.valueOf(termBrand.getId()), webNextUrl,null,null,null);
        }

        return OperationResult.buildSuccessResult("数据保存处理完成", result);
    }


    @Transactional(rollbackFor= Exception.class)
    public void saveTermBrand(List<TermBrandInfo> termBrandList, UpmpPrivilegeCheck privilegeCheck, Long oprMenuId, String oprMenuName, String webNextUrl, HttpServletRequest request)throws RedpException {
        transactionTemplate.execute(new TransactionCallbackWithoutResult(){
            @Override
            protected void doInTransactionWithoutResult(TransactionStatus arg0){
                if(null != termBrandList && termBrandList.size() > 0){
                     UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
                    SimpleDateFormat fmtdt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
                    UpmpOrganization org = organizationService.getOrgByCode(user.getOrgCode(), user.getInstId());
                    String instId = upmpSysParamService.getById(UpmpConstant.IGAS_DEFAULT_INST_ID).getPrimaryValue();
        // 获取渠道ID：固定20
        String channelId = CommonUtils.getChannelId(upmpSysParamService, instId);
                    for(TermBrandInfo termBrand : termBrandList){
                        String lastUpddt=fmtdt.format(new Date());
                        String brandCode = BusinessContainer.BrandCd_PREFIX + String.format("%06d", Integer.parseInt(upmpSysSeqService
                                .updateParamValue(BusinessContainer.COMM_PARAM_CODE, BusinessContainer.BrandCd_PREFIX, channelId)));
                        //终端品牌基本信息
                        termBrand.setBrandCode(brandCode);
                        termBrand.setOprId(user.getId());
                        termBrand.setCreateTime(lastUpddt);
                        if(user.isAdmin()){
                            String instId = request.getParameter("instId");
                            termBrand.setInstId(instId);
                            UpmpOrganization headOrg = organizationService.getHeadOrgByCode(instId);
                            termBrand.setCrtOrgId(headOrg == null ? user.getOrgCode() : headOrg.getOrgCode());
                        }else{
                            termBrand.setInstId(user.getInstId());
                            termBrand.setCrtOrgId(user.getOrgCode());
                        }
                        if(null!=privilegeCheck&& BusinessContainer.YES.equals(privilegeCheck.getChecked())){
                            //需要审核
                            termBrand.setStatus(BizDataStatusEnum.STATUS_DRAFT.getType());
                            termBrand.setAuditStatus(BizDataAuditStatusEnum.AUDIT_STATUS_ADD_CHECKING.getType());
                            if(termBrand.getBrandCode()!=null){
                                save(termBrand);
                            }
                            bizTmpService.saveBizTmp(termBrand, user, org.getInstId(), BizOprEnum.OPR_ADD.getType(), lastUpddt
                                    , String.valueOf(oprMenuId), oprMenuName, termBrand.getStatus(), termBrand.getAuditStatus(), String.valueOf(termBrand.getId()), webNextUrl,null,null,null);

                        }else{
                            //不需要审核
                            termBrand.setStatus(BizDataStatusEnum.STATUS_NORMAL.getType());
                            termBrand.setAuditStatus(BizDataAuditStatusEnum.AUDIT_STATUS_ADD_PASS.getType());
                            if(termBrand.getBrandCode()!=null){
                                save(termBrand);
                            }
                            bizHisService.saveBizHisNew(termBrand,termBrand, user, org.getInstId(), BizOprEnum.OPR_ADD.getType(), lastUpddt, String.valueOf(oprMenuId), oprMenuName, String.valueOf(termBrand.getId()),null,null,null);
                        }
                    }
                }
            }
        });
    }

    public List<Map> selectTermBrand(String brandCode, HttpServletRequest request) {
        String instId = request.getParameter("instId");
         UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
        if(!user.isAdmin()){
            instId = user.getInstId();
        }
        StringBuffer sql = new StringBuffer("select BRAND_CODE,BRAND_NAME from T_B_TERM_BRAND_INFO where INST_ID = '"+instId+"' and STATUS = '01' ");
        if (StringUtils.isNotBlank(brandCode)){
            sql.append("and BRAND_CODE = '"+brandCode+"' ");
        }
        if(!user.isAdmin()){
            sql.append("and CRT_ORG_ID = '"+user.getOrgCode()+"' ");
        }
        Query query = this.getEntityManager().createNativeQuery(sql.toString());
        query.unwrap(SQLQuery.class).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
        List<Map> list = query.getResultList();
        return list;
    }
}
*/
